<template>
  <div class="settlement" v-if="Object.keys(orderList).length!==0">
    <nav-bar title="确认订单" />

    <div class="view-body">
      <div class="address_wrap">
        <div class="tag_wrap">
          <p class="address_head">订单配送至</p>
          <span class="tagtext" v-if="myAddress.tag">{{myAddress.tag}}</span>
        </div>
        <p v-if="myAddress.address" class="address" @click="seleAddress">
          <span class="dizhi">{{myAddress.address}}{{myAddress.bottom}}</span>
          <i class="fa fa-angle-right"></i>
        </p>
        <p v-else class="address" @click="seleAddress">
          <span>选择收获地址</span>
          <i class="fa fa-angle-right"></i>
        </p>
        <div class="bottom">
          <span>{{myAddress.name}}</span>
          <span v-if="myAddress.sex">({{myAddress.sex}})</span>
          <span>{{myAddress.phone}}</span>
        </div>
      </div>
      <div class="checkout-section">
        <div class="time">
          <div class="time-left">
            <span>送达时间</span>
            <span
              v-if="orderList.shopInfo.rst.delivery_mode.text"
              class="text"
            >{{orderList.shopInfo.rst.delivery_mode.text}}</span>
          </div>
          <div class="time-right">
            <span
              class="time-right-text"
            >尽快送达({{deliveryTome(orderList.shopInfo.rst.order_lead_time)}}送达)</span>
            <i class="fa fa-angle-right"></i>
          </div>
        </div>
        <div class="zhifu">
          <span>支付方式</span>
          <span class="zhifu-item">在线支付</span>
        </div>
      </div>
      <div class="shop">
        <h3 class="shop_title">{{orderList.shopInfo.rst.name}}</h3>
        <ul>
          <li class="shop_item" v-for="(item,index) in orderList.selectFoods" :key="index">
            <img class="item_img" :src="item.image_path" alt />
            <div class="name">{{item.name}}</div>
            <span>x{{item.count}}</span>
            <span class="price">￥{{item.specfoods[0].price}}</span>
          </li>
          <li class="shop_item_P">
            <span>配送费</span>
            <span>￥{{orderList.shopInfo.rst.float_delivery_fee}}</span>
          </li>
        </ul>
        <div class="z_Price_wrap">
          小计：
          <span
            class="z_Price"
          >￥{{orderList.totalPrice+orderList.shopInfo.rst.float_delivery_fee}}</span>
        </div>
      </div>

      <div>
        <van-cell @click='handleShow' title="餐具份数" is-link :value="Action|| '未选择'" />
        <van-cell @click="handleNote" title="订单备注" is-link :value="note|| '备注/选填'" />
        <van-cell title="发票信息" is-link value="暂不支支持开发票" />
      </div>
      <van-action-sheet @select='select' title="请选择餐具份数" v-model="show" :actions="actions" cancel-text="取消" @cancel="show=false" />
    </div>
    <remark :note='note' v-if="isNote" @clickleft='clickleft' @handleClick='handleClick'/>
    <div class="buttom">
        <div >
          合计：<span>￥{{orderList.totalPrice+orderList.shopInfo.rst.float_delivery_fee}}</span>
        </div>
        <van-button  round type="info" size='small  ' @click="handelSave(orderList.totalPrice+orderList.shopInfo.rst.float_delivery_fee)">保存</van-button>
    </div>
  </div>
</template>

<script>
import { Cell ,ActionSheet ,Button, Toast } from "vant";
import Remark from './Remark'
import NavBar from "@/views/order/childCpns/NavBar";
export default {
  components: {
    NavBar,
    Remark,
    [Cell.name]: Cell,
    [ActionSheet .name]: ActionSheet,
    [Button .name]: Button,
    [Toast .name]: Toast,
  },
  data() {
    return {
      orderList: {},
      myAddress: {},
      Action: "",
      note: "",
      show:false,
      isNote:false,
      actions:[{name:'1份'},{name:'2份'},{name:'3份'},{name:'4份'},{name:'5份'}]
    };
  },

  activated() {
    this.getData();
  },
  methods: {
    getData() {
      this.orderList = this.$store.getters.orderList;
      this.myAddress = this.$store.getters.myAddress.item || {};
      axios(`/api/user/user_info/${localStorage.token}`).then(res => {});
    },
    seleAddress() {
      this.$router.push("myaddress");
    },
    deliveryTome(time) {
      let date = new Date();
      date.setMinutes(date.getMinutes() + time);
      return date.getHours() + ":" + date.getMinutes();
    },
    handleShow(){
      this.show=true
    },
    select(Action){
      this.Action=Action.name
      this.$store.dispatch('setAddServings',this.Action)
      this.show=false
    },
    handleNote(){
      this.isNote=true
    },
    clickleft(is){
      this.isNote=is
    },
    handleClick(obj){
      this.isNote=obj.isNote
      this.note=obj.message
      this.$store.dispatch('setNote', this.note)
    },
    handelSave(){
      if(!this.myAddress.address){
        Toast('请选择地址');
      }else{
        this.$router.push('/pay')
      }
    }
  }
};
</script>

<style scoped>
.settlement {
  height: 100vh;
}
.view-body {
  margin-top: 0px;
  font-size: 14px;
  display: flex;
  overflow: auto;
  flex-direction: column;
  flex-grow: 1;
  box-sizing: border-box;
  width: 100%;
  height: calc(100vh - 96px);
  padding: 0 15px;
  color: #333333;
  background-image: linear-gradient(
      0deg,
      #f5f5f5,
      #f5f5f5 65%,
      hsla(0, 0%, 96%, 0.3) 75%,
      hsla(0, 0%, 96%, 0)
    ),
    linear-gradient(270deg, #009eef, #009eef);
}
.address{
  width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
}
.address_wrap {
  padding: 10px 15px;
  min-height: 90px;
}
.address_head {
  font-size: 13px;
  color: hsla(0, 0%, 100%, 0.8);
  margin-bottom: 10px;
}
.address > span {
  display: inline-block;
  width:80%;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin-right: 10px;
  margin-bottom: 20px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.address > i {
  font-size: 20px;
  font-weight: 600;
  color: #fff;
}
.checkout-section {
  height: 108px;
  background-color: #fff;
  padding: 0 10px;
}
.time {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px dashed #ccc;
}
.time-left {
  display: flex;
  flex-direction: column;
}
.zhifu {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.shop {
  background-color: #fff;
  padding: 10px 15px;
  margin: 10px 0;
}
.shop_title {
  font-size: 16px;
  margin-bottom: 20px;
}
.item_img {
  width: 38px;
  height: 38px;
}
.shop_item {
  height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed #ccc;
}
.shop_item_P {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed #ccc;
}
.z_Price_wrap {
  float: right;
  margin-top: 20px;
  font-size: 13.5px;
}
.z_Price {
  font-size: 18px;
  font-weight: 600;
  color: #009eef;
}
.tag_wrap {
  display: flex;
}
.tagtext {
  margin-left: 8px;
  font-size: 14px;
  color: #0c0209;
}
.bottom {
  color: rgba(255, 255, 255, 0.8);
}
.bottom > span:nth-last-of-type(1) {
  margin-left: 20px;
}
.text {
  color: #fff;
  padding: 2px;
  font-size: 12px;
  margin-top: 5px;
  background-image: linear-gradient(90deg, #0af, #0085ff);
}
.time-right-text {
  margin-right: 5px;
}
.time-right {
  color: #0085ff;
}
.zhifu-item {
  color: #0085ff;
}
.buttom{
  height: 50px;
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
}

</style>